/**
 * Copyright 2011 The Apache Software Foundation
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package idv.takeshi.model;

import org.apache.commons.lang.builder.EqualsBuilder;


/**
 * @author takeshi.miao
 *
 */
public class RoleRelationship extends Entity<RoleRelationship> {
	
	private static final long serialVersionUID = -6046062148932426009L;
	
	private Long personId;
	
	private Long roleId;
	
	private Role role;
	
	/**
	 * @return the personId
	 */
	public Long getPersonId() {
		return personId;
	}

	/**
	 * @param personId the personId to set
	 */
	public void setPersonId(Long personId) {
		this.personId = personId;
	}

	/**
	 * @return the roleId
	 */
	public Long getRoleId() {
		return roleId;
	}

	/**
	 * @param roleId the roleId to set
	 */
	public void setRoleId(Long roleId) {
		this.roleId = roleId;
	}

	/**
	 * @return the role
	 */
	public Role getRole() {
		return role;
	}

	/**
	 * @param role the role to set
	 */
	public void setRole(Role role) {
		this.role = role;
	}

	@Override
	public boolean equalsByKey(RoleRelationship roleRelationship) {
		if(null == roleRelationship) return false;
		return new EqualsBuilder()
			.append(this.personId, roleRelationship.personId)
			.append(this.roleId, roleRelationship.roleId)
			.isEquals();
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (obj == null) { return false; }
		if (obj == this) { return true; }
		if (!(obj instanceof RoleRelationship)) {
			return false;
		}
		RoleRelationship roleRelationship = (RoleRelationship)obj;
		return this.equalsByKey(roleRelationship);
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		return this.personId.hashCode() + this.roleId.hashCode();
	}

}
